import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { viteMockServe } from 'vite-plugin-mock'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  loadEnv(mode, process.cwd(), '')
  return {
    base: './',
    plugins: [vue(),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
    }),
    viteMockServe({
      mockPath: "./mock",
      localEnablid: !!(command === 'serve'),
      // enable: !!(command === 'serve')
    })
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src")
      }
    },
    build: {
      outDir: mode == 'development' ? 'accounting_dev' : 'accounting'
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: `@import "./src/assets/scss/variable.scss"; @import "./src/assets/scss/reset.scss";`
        }
      }
    },
    server: {
      hmr: true,
      host: '0.0.0.0',
      port: 3001,
      proxy: {
        '/api': {
          ws: false,
          changeOrigin: true,
          target: 'http://10.9.18.168:7777'
        },
        // '/auto': {
        //   ws: false,
        //   changeOrigin: true,
        //   target: 'https://appservice.epicc.com.cn'
        // },
      },
      cors: true
    }
  }
})
